package com.atguigu.guli.service.edu.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.atguigu.guli.service.base.exception.GuliException;
import com.atguigu.guli.service.base.result.ResultCodeEnum;
import com.atguigu.guli.service.edu.entity.Subject;
import com.atguigu.guli.service.edu.entity.excel.ExcelSubject;
import com.atguigu.guli.service.edu.entity.vo.ExcelSubjectVo;
import com.atguigu.guli.service.edu.entity.vo.SubjectVo;
import com.atguigu.guli.service.edu.listener.ExcelSubjectListener;
import com.atguigu.guli.service.edu.mapper.SubjectMapper;
import com.atguigu.guli.service.edu.service.SubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 课程科目 服务实现类
 * </p>
 *
 * @author Miluo
 * @since 2020-10-14
 */
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements SubjectService {

    @Autowired
    SubjectMapper subjectMapper;

    @Override
    public void saveExcelSubject(MultipartFile file) {
//        try {
        try {
            EasyExcel.read(file.getInputStream(), ExcelSubject.class,new ExcelSubjectListener(subjectMapper)).sheet(0).doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
//        } catch (Exception e) {
//            throw new GuliException(ResultCodeEnum.EXCEL_DATA_IMPORT_ERROR);
//        }
    }

    @Override
    public List<ExcelSubjectVo> subjectList() {
        return subjectMapper.selectSubjectVoList();
    }

    @Override
    public List<SubjectVo> nestedList() {
        List<SubjectVo> subjectVos = subjectMapper.courseSubjectVoList();
        return subjectVos;
    }


}
